package com.expressage.controller;

import com.expressage.po.Sort;
import com.expressage.service.SortService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * 快递类别控制器
 */

@Controller
public class SortController {

    Logger logger = Logger.getLogger(SortController.class);

    @Autowired
    SortService sortService;

    @RequestMapping("/sortlist")
    public String findAll(Model model){
        logger.info("进入了快递类别集合控制器");
        List<Sort> list = sortService.findAll();
        model.addAttribute("list",list);
        return "jspafter/sortlist";
    }

    @RequestMapping("/toaddsort")
    public String toadd(Model model){
        logger.info("进入了去添加控制器");
        return "jspafter/addsort";
    }

    @RequestMapping("/addsort")
    public String add(Sort sort){
        logger.info("进入了添加快递类别控制器");
        Boolean flag =  sortService.insert(sort);
        logger.info(flag?"添加员工成功":"添加员工失败");
        return "redirect:sortlist.action";
    }

    @RequestMapping("/toupdatesort")
    public String toupdate(int sortid,Model model){
        logger.info("进入了去修改控制器");
        Sort sort = sortService.findBySortid(sortid);
        model.addAttribute("sort",sort);
        return "jspafter/updatesort";
    }

    @RequestMapping("/updatesort")
    public String updatesort(Sort sort){
        logger.info("进入了添加控制器");
        Boolean flag = sortService.update(sort);
        logger.info(flag?true:false);
        return "redirect:sortlist.action";
    }

    @RequestMapping("/deletesort")
    public String deleteSort(int[] sortid){
        logger.info("进入了删除控制器");
        Boolean flag = sortService.delete(sortid);
        return "redirect:sortlist.action";
    }
}
